package com.snopy.designPattern.create.prototype;

import com.snopy.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author snopy
 * @version 1.0.0
 * @classname CloneDemo
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/01 22:06
 */
@Slf4j
public class CloneDemo {
    public static void main(String[] args) {
            long l1 = System.currentTimeMillis();
            for (int i = 0;i<100;i++){
                    User user = new User();
                    user.setAddr("上海市浦东新区周浦东航头路169弄4号603");
                    user.setGender("男");
                    user.setName("snopy");
                    user.setAge(20);
                    Order order = new Order();
                    order.setTotal(1000.0);
                    order.setOrderTime(DateUtil.stringToDate("2020-01-01","yyyy-MM-dd"));
                    user.setOrder(order);
                    Address address = new Address();
                    address.setCity("上海市");
                    address.setProvince("上海市");
                    address.setConcact("15555555555");
                    address.setHouseNum("4603");
                    address.setStreet("航头路169弄");
                    address.setTown("4号");
                    address.setPostCode("236200");
                    List<Address> list = new ArrayList<>();
                    user.setRecAddr(list);
            }
            long l2 = System.currentTimeMillis();
            User user = new User();
            user.setAddr("上海市浦东新区周浦东航头路169弄4号603");
            user.setGender("男");
            user.setName("snopy");
            user.setAge(20);
            Order order = new Order();
            order.setTotal(1000.0);
            order.setOrderTime(DateUtil.stringToDate("2020-01-01","yyyy-MM-dd"));
            user.setOrder(order);
            Address address = new Address();
            address.setCity("上海市");
            address.setProvince("上海市");
            address.setConcact("15555555555");
            address.setHouseNum("4603");
            address.setStreet("航头路169弄");
            address.setTown("4号");
            address.setPostCode("236200");
            List<Address> list = new ArrayList<>();
            user.setRecAddr(list);
            for (int i = 0;i<100;i++){
                    User clone = user.clone();
            }
            long l3= System.currentTimeMillis();
            log.info("new cost time:{}",l2 - l1);
            log.info("clone cost time:{}",l3 - l2);
            user = new User();
            user.setAddr("上海市浦东新区周浦东航头路169弄4号603");
            user.setGender("男");
            user.setName("snopy");
            user.setAge(20);
            order = new Order();
            order.setTotal(1000.0);
            order.setOrderTime(DateUtil.stringToDate("2020-01-01","yyyy-MM-dd"));
            user.setOrder(order);
            address = new Address();
            address.setCity("上海市");
            address.setProvince("上海市");
            address.setConcact("15555555555");
            address.setHouseNum("4603");
            address.setStreet("航头路169弄");
            address.setTown("4号");
            address.setPostCode("236200");
            list = new ArrayList<>();
            list.add(address);
            user.setRecAddr(list);
            log.info("user:{}",user);

            User user1 = user.clone();
            log.info("user1:{}",user1);
            order.setTotal(2000.0);
            address.setStreet("阳川路");
            log.info("user1:{}",user1);
    }
}
